package com.yanfan.energy.controller;


import com.yanfan.common.annotation.Anonymous;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.domain.entity.SysUser;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.energy.domain.Consumables;
import com.yanfan.energy.service.ConsumablesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/energy/consumables")
public class ConsumablesController extends BaseController {

    @Autowired
    private ConsumablesService consumablesService;

    @GetMapping("/list")
    @ApiOperation("设备分页列表")
    public TableDataInfo list(Consumables consumables) {
        startPage();
        return getDataTable(consumablesService.selectConfiguration(consumables));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody Consumables consumables) {
        int i = consumablesService.addConfiguration(consumables);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Consumables consumables) {
        int i = consumablesService.updateConfiguration(consumables);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @GetMapping("/delete")
    public AjaxResult delete(Long configurationId) {
        int i = consumablesService.deleteConfiguration(configurationId);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("/ConsumableShenQian")
    public AjaxResult getConsumableShenQian(@RequestBody Consumables consumables) {
        return consumablesService.getConsumableShenQian(consumables);
    }

    @ApiOperation("能源流向列表")
    @GetMapping("/energyFlowsList")
    @Anonymous
    public TableDataInfo energyFlowsList(Consumables consumables) {
        startPage();
        return getDataTable(consumablesService.energyFlowsList(consumables));
    }

    @PostMapping("/ConsumablePangMing")
    @Anonymous
    public AjaxResult getConsumablePangMing(@RequestBody Consumables consumables) {
        return AjaxResult.success(consumablesService.getConsumablePangMing(consumables));
    }

    @PostMapping("/ConsumableShuJuZhanBi")
    public AjaxResult getConsumableShuJuZhanBi(@RequestBody Consumables consumables) {
        return consumablesService.getConsumableShuJuZhanBi(consumables);
    }

    @PostMapping("/ConsumableShuJuQuShi")
    public AjaxResult getConsumableShuJuQuShi(@RequestBody Consumables consumables) {
        return consumablesService.getConsumableShuJuQuShi(consumables);
    }
}
